3300 #include "types.h"
3301 #include "x86.h"
3302 #include "defs.h"
3303 #include "param.h"
3304 #include "mmu.h"
3305 #include "proc.h"
3306 
3307 int
3308 sys_fork(void)
3309 {
3310   return fork();
3311 }
3312 
3313 int
3314 sys_exit(void)
3315 {
3316   exit();
3317   return 0;  // not reached
3318 }
3319 
3320 int
3321 sys_wait(void)
3322 {
3323   return wait();
3324 }
3325 
3326 int
3327 sys_wait2(void)
3328 {
3329 
3330 int t1, t2;
3331 	if ((argint(0, &t1) < 0) | (argint(1, &t2) < 0) )
3332 		return -1;
3333 	return wait2(&t1, &t2);
3334 }
3335 
3336 int
3337 sys_nice(void)
3338 {
3339 
3340 	return nice();
3341 }
3342 
3343 
3344 
3345 
3346 
3347 
3348 
3349 
3350 int
3351 sys_kill(void)
3352 {
3353   int pid;
3354 
3355   if(argint(0, &pid) < 0)
3356     return -1;
3357   return kill(pid);
3358 }
3359 
3360 
3361 
3362 int
3363 sys_getpid(void)
3364 {
3365   return proc->pid;
3366 }
3367 
3368 int
3369 sys_sbrk(void)
3370 {
3371   int addr;
3372   int n;
3373 
3374   if(argint(0, &n) < 0)
3375     return -1;
3376   addr = proc->sz;
3377   if(growproc(n) < 0)
3378     return -1;
3379   return addr;
3380 }
3381 
3382 int
3383 sys_sleep(void)
3384 {
3385   int n;
3386   uint ticks0;
3387 
3388   if(argint(0, &n) < 0)
3389     return -1;
3390   acquire(&tickslock);
3391   ticks0 = ticks;
3392   while(ticks - ticks0 < n){
3393     if(proc->killed){
3394       release(&tickslock);
3395       return -1;
3396     }
3397     sleep(&ticks, &tickslock);
3398   }
3399   release(&tickslock);
3400   return 0;
3401 }
3402 
3403 // return how many clock tick interrupts have occurred
3404 // since boot.
3405 int
3406 sys_uptime(void)
3407 {
3408   uint xticks;
3409 
3410   acquire(&tickslock);
3411   xticks = ticks;
3412   release(&tickslock);
3413   return xticks;
3414 }
3415 
3416 
3417 
3418 
3419 
3420 
3421 
3422 
3423 
3424 
3425 
3426 
3427 
3428 
3429 
3430 
3431 
3432 
3433 
3434 
3435 
3436 
3437 
3438 
3439 
3440 
3441 
3442 
3443 
3444 
3445 
3446 
3447 
3448 
3449 
